//
//  MyWalletViewController.m
//  Logistics
//
//  Created by hy002 on 2018/1/22.
//  Copyright © 2018年 HUYU. All rights reserved.
//

#import "MyWalletViewController.h"

@interface MyWalletViewController ()
{
    UILabel *integraLab;
    UILabel *shareLab;
    UILabel *lookLab;
    UILabel *regisLab;
    UILabel *certiLab;
}
@end

@implementation MyWalletViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUI];
    [self requestMyWallet];
}

- (void)creatUI
{
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"我的钱包";
    self.view.backgroundColor = [UIColor whiteColor];
    UIImageView *integralView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH/2-50*displaywidth, 50*displaywidth, 100*displaywidth, 100*displaywidth) ImageName:@"my_icon18"];
    integralView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:integralView];
    integraLab = [ZCControl createLabelWithFrame:CGRectMake(0, 180*displaywidth, SCREEN_WIDTH, 45*displaywidth) Font:40.0 Text:@"600" Color:BlaTitColor];
    integraLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:integraLab];
    UILabel *toseAlab = [ZCControl createLabelWithFrame:CGRectMake(0, 230*displaywidth, SCREEN_WIDTH, 20*displaywidth) Font:14.0 Text:@"我的积分" Color:RGB(136, 136, 136)];
    toseAlab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:toseAlab];
    NSArray *colorsAry = @[RGB(29, 220, 156),RGB(122, 173, 224),RGB(255, 183, 0),RGB(237, 75, 75)];
    NSArray *imgAry = @[@"my_icon19",@"my_icon20",@"my_icon21",@"my_icon22"];
    NSArray *nameAry = @[@"分享次数",@"浏览次数",@"注册人数",@"入驻人数"];
    CGFloat W = (SCREEN_WIDTH-60*displaywidth)/4;
    for (int i = 0; i < imgAry.count; i++)
    {
        UIView *backV = [[UIView alloc] initWithFrame:CGRectMake(15*displaywidth+(W+10*displaywidth)*i, 300*displaywidth, W, W)];
        backV.backgroundColor = colorsAry[i];
        [self.view addSubview:backV];
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(W/2-12.5*displaywidth, 13*displaywidth, 25*displaywidth, 25*displaywidth) ImageName:imgAry[i]];
        imgView.contentMode = UIViewContentModeScaleAspectFit;
        [backV addSubview:imgView];
        UILabel *numLab = [ZCControl createLabelWithFrame:CGRectMake(0, 50*displaywidth, W, 20*displaywidth) Font:17.0 Text:@"12000" Color:[UIColor whiteColor]];
        numLab.textAlignment = NSTextAlignmentCenter;
        [backV addSubview:numLab];
        UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth+(W+10*displaywidth)*i, 300*displaywidth+W, W, 30*displaywidth) Font:14.0 Text:nameAry[i] Color:RGB(136, 136, 136)];
        nameLab.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:nameLab];
        if (i == 0)
        {
            shareLab = numLab;
        }
        else if (i == 1)
        {
            lookLab = numLab;
        }
        else if (i == 2)
        {
            regisLab = numLab;
        }
        else
        {
            certiLab = numLab;
        }
    }
    
    UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, SCREEN_HEIGHT-STA_NAV_HEIGHT-SCREER_HeiX-55*displaywidth, SCREEN_WIDTH-30*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(soureBtnAction) Title:@"分享" Font:18.0];
    soureBtn.backgroundColor = RGB(255, 153, 0);
    [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    soureBtn.layer.cornerRadius = 5;
    soureBtn.layer.masksToBounds = YES;
    [self.view addSubview:soureBtn];
}

- (void)soureBtnAction
{
    UserAccountModel *model = [UserAccountModel shareMange];
    ShareManager *manager = [ShareManager shareToManager];
    manager.title = @"专线网";
    manager.descriptionStr = @"查专线，查运价，就上专线网";
    manager.imgUrl = @"logo3x60";
    manager.webUrl = [NSString stringWithFormat:@"https://new.wuliu.xin/?inviteUserId=%ld",model.ID];
}

- (void)requestMyWallet
{
    WEAKSELF;
    [HYBaseHandler requestWithTheFormUrl:SERVER_walletMine Parmers:nil Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            NSString *integral = obj[@"data"][@"integral"];
            NSString *share = obj[@"data"][@"shareCount"];
            NSString *lookstr = obj[@"data"][@"viewCount"];
            NSString *payment = obj[@"data"][@"paymentCount"];
            NSString *signIn = obj[@"data"][@"signInCount"];
            dispatch_async(dispatch_get_main_queue(), ^{
                integraLab.text = s_str(integral);
                shareLab.text = s_str(share);
                lookLab.text = s_str(lookstr);
                regisLab.text = s_str(payment);
                certiLab.text = s_str(signIn);
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
